其他
使用Qiling IDA插件解密Mirai病毒数据
本文为看雪论坛优秀文章
看雪论坛作者ID:kabeor
介绍
安装
安装Qiling
安装插件
插件的安装方式有两种:
# Linux
ln -s /absolute/path/to/qiling/extensions/idaplugin/qilingida.py /path/to/your/ida/plugins/
# Macos
ln -s /absolute/path/to/qiling/extensions/idaplugin/qilingida.py /Applications/<Your IDA>/ida.app/Contents/MacOS/plugins/
# Windows
mklink C:\absolute\path\to\IDA\plugins\qilingida.py D:\absolute\path\to\qiling\extensions\idaplugin\qilingida.py
IDA在启动时会自动加载Qiling插件。
支持状态
- : 不适用
☐: 不支持
☑: 支持
使用Qiling IDA插件
解密Mirai
视频展示
编写插件自定义脚本
class QILING_IDA():
def __init__(self):
pass
def custom_prepare(self, ql): # Qiling初始化时调用
pass
def custom_continue(self, ql:Qiling): # 点击“Continue”按钮时调用
hook = []
return hook
def custom_step(self, ql:Qiling, stepflag): # 点击“Step”按钮时调用
hook = []
return hook
import struct
from qiling import *
def show_encode_string_memory_address(ql:Qiling):
# 显示待解密buffer所在地址
memory_address_bytes = bytes(ql.mem.read(ql.reg.read('LR'), 0x4))
memory_address = hex(struct.unpack('<I', memory_address_bytes)[0])
print('encode_string_memory_address at: '+memory_address)
def hook_LR(ql:Qiling, encoded_message_ascii):
encode_string_length=len(encoded_message_ascii)
encode_bytes_length=encode_string_length.to_bytes(length=1, byteorder='big')
# 在内存中覆写待解密buffer的长度
ql.mem.write(ql.reg.read('LR')+0x4, encode_bytes_length)
memory_address_bytes = bytes(ql.mem.read(ql.reg.read('LR'), 0x4))
memory_address = hex(struct.unpack('<I', memory_address_bytes)[0])
memory_address = int(memory_address, 16)
# 将待解密buffer中的值替换为我们需要解密的数据
new_encode=b''
for x in encoded_message_ascii:
new_encode += x.to_bytes(length=1, byteorder='big')
ql.mem.write(memory_address, new_encode)
print('Encode: ', bytes(ql.mem.read(memory_address, len(encoded_message_ascii))))
def decode_show(ql, encoded_message_ascii):
# 读取待解密buffer中的值
encode_string_length=len(encoded_message_ascii)
memory_address_bytes = bytes(ql.mem.read(ql.reg.read('LR'), 0x4))
memory_address = hex(struct.unpack('<I', memory_address_bytes)[0])
memory_address = int(memory_address, 16)
print('Decode: ', bytes(ql.mem.read(memory_address, encode_string_length)).replace(b'T', b' '))
class QILING_IDA():
def __init__(self):
pass
def custom_prepare(self, ql):
ql.patch(0xF58C, b'\x90\x90\x90\x90\x90') # 将该地址的clock函数nop,否则无法继续模拟
# 读取加密数据,转换格式
encoded_message_bytes = bytes(ql.mem.read(0x1393C, 0x1395B-0x1393C))
encoded_message_ascii = []
for i in encoded_message_bytes:
encoded_message_ascii.append(i)
# 显示待解密buffer所在地址,便于在内存中查看结果
ql.hook_address(show_encode_string_memory_address, 0x12A68)
# 将加密数据写入LR指向的内存地址
ql.hook_address(hook_LR, 0x12A70, user_data=encoded_message_ascii)
def custom_continue(self, ql:Qiling):
# 读取加密数据,转换格式
encoded_message = bytes(ql.mem.read(0x1393C, 0x1395B-0x1393C))
encoded_message_ascii = []
for i in encoded_message:
encoded_message_ascii.append(i)
# 显示每循环一次后当前内存的解密状态
decode_show_hook = ql.hook_address(decode_show, 0x12AC8, user_data=encoded_message_ascii)
# 返回该hook的handle,插件将自动处理
hook = [decode_show_hook]
return hook
def custom_step(self, ql:Qiling, stepflag):
hook = []
return hook
初始化插件
运行插件进行解密
总结
https://github.com/qilingframework/qiling/issues
看雪ID:kabeor
https://bbs.pediy.com/user-home-787320.htm
*本文由看雪论坛 kabeor 原创,转载请注明来自看雪社区。
推荐文章++++
求分享
求点赞
求在看